import * as step from '@ali/flow-step-toolkit'
import dockerToolkit from '@flow-step/dockertoolkit';
import process from 'process'
import {setup} from "./setup";

const DOCKER_REPOSITORY: string = 'DOCKER_REPOSITORY'

async function runStep(): Promise<void> {
    dockerToolkit.checkDockerInstallation()

    const dockerRepository: string | undefined =
        process.env[DOCKER_REPOSITORY]

    if (dockerRepository == undefined) {
        throw new Error('missing DOCKER_REPOSITORY')
    }

    await setup(dockerRepository)
}

runStep()
    .then(function () {
        step.success('run step successfully!')
    })
    .catch(function (err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
